package cn.edu.lcu.cs.javaprogramming.gui;

import javax.swing.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;

/**
 * TODO 这里是文档说明，如果未提供，把本行删除。
 *
 * @author ling
 * @date 2022/5/12 9:12
 */
public class MouseDemoFrame {
    private JButton button1;
    private JPanel contentPanel;
    private JTextArea textArea1;

    public MouseDemoFrame() {

        textArea1.addMouseMotionListener(new MouseMotionAdapter() {
            @Override
            public void mouseMoved(MouseEvent e) {
                textArea1.setText("(" + e.getX() + "," + e.getY() + ")");
            }
        });
    }

    public static void main(String[] args) {
        JFrame frame = new JFrame("鼠标演示");
        frame.setContentPane(new MouseDemoFrame().contentPanel);
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        //frame.setSize(800, 600);
        frame.pack();
        frame.setVisible(true);
    }
}
